import 'package:word_game/engine/core.dart';
import 'task.dart';
import 'taskable_hero.dart';

class DeliverEvent extends Eventable {
  DeliverEvent() : super('交付');

  @override
  void doEvent(owner) {
    var task = owner as Task;
    var hero = World.instance.hero as TaskableHero;
    if (!task.expecta.expecta(hero, task)) {
      Engine.instance.displayer.displayString('任务尚未完成。');
      return;
    }
    task.owner.taskStates['${task.code}_${hero.name}'] = 'deliver';
    hero.tasks.removeWhere((item)=>item.code==task.code);
    hero.pureRemoveThingByCode(task.thingCode);
    Engine.instance.displayer.displayString('[${hero.name}]交付了任务[${task.name}]。');
    if (task.rewardThingCode!=null && task.rewardThingCode.isNotEmpty) {
      World.instance.hero.getThing(MaterialManager.instance.newMaterialWithCode(task.rewardThingCode));
    }
  }
}